{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d6844286-e97c-462c-b72e-9ef5b38f95d8",
   "metadata": {},
   "source": [
    "# <center>GuessGame</center>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f40f478b-c793-4a7f-ac0e-78d3abab0f9e",
   "metadata": {},
   "source": [
    "## 业务需求："
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ad22ace1-2d04-4694-a6ff-8f13e55b816e",
   "metadata": {},
   "source": [
    "详细需求：</br>\n",
    "&ensp;&ensp;&ensp;1.\t系统随机产生一个随机数</br>\n",
    "&ensp;&ensp;&ensp;2.\t用户从键盘输入猜的数字</br>\n",
    "&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;a)\t系统判断数字是否比系统产生的大，若大了，则友好提示：大了</br>\n",
    "&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;b)\t若小了，则提示小了</br>\n",
    "&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;c)\t否则，则提示：恭喜猜中，本轮幸运数字：xxx</br>\n",
    "技术选型：</br>\n",
    "&ensp;&ensp;&ensp;1.\t随机数：random</br>\n",
    "&ensp;&ensp;&ensp;2.\t输入：input</br>\n",
    "&ensp;&ensp;&ensp;3.\t判断：if…elif…elif…else</br>\n",
    "&ensp;&ensp;&ensp;4.\t循环：while,for循环</br>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "874b5ca4-a54e-4875-99af-3712abaec064",
   "metadata": {},
   "source": [
    "### version==1.0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "cd920ea8-9e0e-405b-8560-1aaf33d4d4ae",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "欢迎使用GuessGame小游戏！\n",
      "\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "是否开始游戏(Y/y为是，N/n为否): y\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "正在进入游戏\n",
      "\n",
      "系统随机幸运数字已生成,友情提示数字范围提醒:0-100(包括0和100)，游戏开始\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 50\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字大于幸运数\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 25\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字小于幸运数\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 35\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字大于幸运数\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 28\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字大于幸运数\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 27\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字大于幸运数\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 26\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "恭喜您猜对了，本轮幸运数字为： 26\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "本轮游戏结束，请选择是否继续游戏(Y/y为是，N/n为否): n\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "正在退出游戏，感谢您的使用，欢迎下次使用...\n"
     ]
    }
   ],
   "source": [
    "import time\n",
    "import random\n",
    "\n",
    "print(\"欢迎使用GuessGame小游戏！\\n\")\n",
    "sel = str(input('是否开始游戏(Y/y为是，N/n为否):'))  # 获取用户选择\n",
    "\n",
    "\n",
    "# 定义数字猜测游戏函数\n",
    "def guess():\n",
    "    tmp = random.randint(0, 101)  # 生成0-100的随机数\n",
    "    print('系统随机幸运数字已生成,友情提示数字范围提醒:0-100(包括0和100)，游戏开始')\n",
    "    i = 0\n",
    "    while i == 0:  # 设置循环条件，满足条件循环，不满足退出\n",
    "        tmp = tmp\n",
    "        # print(tmp)  # 打印生成的随机数，用于可靠性验证\n",
    "        using = int(input('请输入您猜测的数字:'))\n",
    "        # 判断输入的数字与系统生成的随机数的关系\n",
    "        if using < 0 or using > 100:\n",
    "            print('对不起，您输入的数字超出预定范围，请重新输入')\n",
    "        elif using > tmp:\n",
    "            print('对不起，您输入的数字大于幸运数')\n",
    "        elif using < tmp:\n",
    "            print('对不起，您输入的数字小于幸运数')\n",
    "        elif using == tmp:\n",
    "            print('恭喜您猜对了，本轮幸运数字为：', tmp)\n",
    "            sre = input(\"本轮游戏结束，请选择是否继续游戏(Y/y为是，N/n为否):\")\n",
    "            if sre.upper() == 'Y':\n",
    "                i = 0\n",
    "                print('正在重新生成系统随机幸运数字...')\n",
    "                time.sleep(1)\n",
    "                tmp = random.randint(0, 101)  # 生成0-100的随机数\n",
    "                print(\"新的幸运数字已生成，游戏继续...\")\n",
    "            elif sre.upper() == 'N':\n",
    "                print(\"正在退出游戏，感谢您的使用，欢迎下次使用...\")\n",
    "                i = 1\n",
    "            else:\n",
    "                print(\"输入错误！\")\n",
    "        else:\n",
    "            print(\"输入错误！\")\n",
    "\n",
    "\n",
    "if sel.upper() == 'Y':  # 判断用户的选择\n",
    "    print(\"正在进入游戏\\n\")\n",
    "    time.sleep(0.5)  # 时间暂停0.5秒\n",
    "    guess()\n",
    "elif sel.upper() == 'N':\n",
    "    print('正在退出程序...')\n",
    "    time.sleep(1)\n",
    "    exit()\n",
    "else:\n",
    "    print(\"输入错误!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "52d02a63-e880-4117-bfab-164217c1af5a",
   "metadata": {},
   "source": [
    "### version==2.0"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ff30a990-3a29-4b9d-a6db-97a4c1cff523",
   "metadata": {},
   "source": [
    "在基于1.0版本的需求之上，添加新需求：<br>\n",
    "&ensp;&ensp;&ensp;玩家起始有5000金币，每猜错一次扣500金币，猜对了即奖励3000金币，游戏结束<br>\n",
    "&ensp;&ensp;&ensp;一直到本金余额不足为止。游戏退出。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "75e76d91-8a41-47cb-8c16-f084ed6d1d21",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "欢迎使用GuessGame小游戏！\n",
      "\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "是否开始游戏(Y/y为是，N/n为否): y\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "正在进入游戏\n",
      "\n",
      "系统随机幸运数字已生成,友情提示数字范围提醒:0-100(包括0和100)，游戏开始\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 50\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字大于幸运数，金币数量减500，剩余金币： 4500\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 25\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字小于幸运数,金币数量减500，剩余金币： 4000\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 27\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字小于幸运数,金币数量减500，剩余金币： 3500\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 28\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字小于幸运数,金币数量减500，剩余金币： 3000\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 35\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字大于幸运数，金币数量减500，剩余金币： 2500\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 33\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字小于幸运数,金币数量减500，剩余金币： 2000\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 34\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "恭喜您猜对了，金币数量加3000，现有金币数量5000,本轮幸运数字为：34\n",
      "正在重新生成系统随机幸运数字...\n",
      "新的幸运数字已生成，游戏继续...\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 12\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字小于幸运数,金币数量减500，剩余金币： 4500\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 12\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字小于幸运数,金币数量减500，剩余金币： 4000\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 12\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字小于幸运数,金币数量减500，剩余金币： 3500\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 12\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字小于幸运数,金币数量减500，剩余金币： 3000\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 12\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字小于幸运数,金币数量减500，剩余金币： 2500\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 12\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字小于幸运数,金币数量减500，剩余金币： 2000\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 12\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字小于幸运数,金币数量减500，剩余金币： 1500\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 12\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字小于幸运数,金币数量减500，剩余金币： 1000\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 13\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字小于幸运数,金币数量减500，剩余金币： 500\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 12\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字小于幸运数,金币数量减500，剩余金币： 0\n",
      "当前剩余金币为0,不满足游戏条件，游戏退出\n"
     ]
    }
   ],
   "source": [
    "import time\n",
    "import random\n",
    "\n",
    "print(\"欢迎使用GuessGame小游戏！\\n\")\n",
    "sel = str(input('是否开始游戏(Y/y为是，N/n为否):'))  # 获取用户选择\n",
    "\n",
    "\n",
    "# 定义数字猜测游戏函数\n",
    "def guess():\n",
    "    tmp = random.randint(0, 101)  # 生成0-100的随机数\n",
    "    print('系统随机幸运数字已生成,友情提示数字范围提醒:0-100(包括0和100)，游戏开始')\n",
    "    mon = 5000  # 定义初始金币数量\n",
    "    while mon >= 500:  # 设置循环条件，满足条件循环，不满足退出\n",
    "        tmp = tmp\n",
    "        # print(tmp)  # 打印生成的随机数，用于可靠性验证\n",
    "        using = int(input('请输入您猜测的数字:'))\n",
    "        # 判断输入的数字与系统生成的随机数的关系\n",
    "        if using < 0 or using > 100:\n",
    "            print('对不起，您输入的数字超出预定范围，请重新输入')\n",
    "        elif using > tmp:\n",
    "            print('对不起，您输入的数字大于幸运数，金币数量减500，剩余金币：', mon - 500)\n",
    "            mon = mon - 500\n",
    "        elif using < tmp:\n",
    "            print('对不起，您输入的数字小于幸运数,金币数量减500，剩余金币：', mon - 500)\n",
    "            mon = mon - 500\n",
    "        elif using == tmp:\n",
    "            print('恭喜您猜对了，金币数量加3000，现有金币数量{},本轮幸运数字为：{}'.format(mon + 3000, tmp))\n",
    "            mon = mon + 3000\n",
    "            print('正在重新生成系统随机幸运数字...')\n",
    "            time.sleep(1)\n",
    "            tmp = random.randint(0, 101)  # 生成0-100的随机数\n",
    "            print(\"新的幸运数字已生成，游戏继续...\")\n",
    "        else:\n",
    "            print('输入错误！')\n",
    "            break\n",
    "    else:\n",
    "        print(\"当前剩余金币为{},不满足游戏条件，游戏退出\".format(mon))\n",
    "\n",
    "\n",
    "if sel.upper() == 'Y':  # 判断用户的选择\n",
    "    print(\"正在进入游戏\\n\")\n",
    "    time.sleep(0.5)  # 时间暂停0.5秒\n",
    "    guess()\n",
    "elif sel.upper() == 'N':\n",
    "    print('正在退出程序...')\n",
    "    time.sleep(1)\n",
    "    exit()\n",
    "else:\n",
    "    print('输入错误！')\n",
    "    exit()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0cb4284d-8008-4c4f-a939-1ff148308668",
   "metadata": {},
   "source": [
    "### version==3.0"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "baf026cc-f493-43fc-afcf-bc767f8e6103",
   "metadata": {},
   "source": [
    "在1.0或者2.0 的基础上添加一个新功能：<br>\n",
    "&ensp;&ensp;&ensp;玩家在猜中后，系统需要询问玩家是否继续下一轮游戏。<br>\n",
    "&ensp;&ensp;&ensp;若继续：则继续下一轮。并重新生成一个随机数字。<br>\n",
    "&ensp;&ensp;&ensp;否则，系统退出。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "52a0d68f-d311-48ce-a9af-4c27325163ee",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "欢迎使用GuessGame小游戏！\n",
      "\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "是否开始游戏(Y/y为是，N/n为否): y\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "正在进入游戏\n",
      "\n",
      "系统随机幸运数字已生成,友情提示数字范围提醒:0-100(包括0和100)，游戏开始\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 50\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字小于幸运数,金币数量减500，剩余金币： 4500\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 98\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字大于幸运数，金币数量减500，剩余金币： 4000\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 75\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字小于幸运数,金币数量减500，剩余金币： 3500\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 85\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字大于幸运数，金币数量减500，剩余金币： 3000\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 78\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字大于幸运数，金币数量减500，剩余金币： 2500\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 77\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字大于幸运数，金币数量减500，剩余金币： 2000\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 76\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "恭喜您猜对了，金币数量加3000，现有金币数量5000,本轮幸运数字为：76\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "本轮游戏结束，请选择是否继续游戏(Y/y为是，N/n为否): y\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "正在重新生成系统随机幸运数字...\n",
      "新的幸运数字已生成，游戏继续...\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 30\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字小于幸运数,金币数量减500，剩余金币： 4500\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 58\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字小于幸运数,金币数量减500，剩余金币： 4000\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 85\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字大于幸运数，金币数量减500，剩余金币： 3500\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 75\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字小于幸运数,金币数量减500，剩余金币： 3000\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 78\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字小于幸运数,金币数量减500，剩余金币： 2500\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 76\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字小于幸运数,金币数量减500，剩余金币： 2000\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 77\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对不起，您输入的数字小于幸运数,金币数量减500，剩余金币： 1500\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入您猜测的数字: 80\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "恭喜您猜对了，金币数量加3000，现有金币数量4500,本轮幸运数字为：80\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "本轮游戏结束，请选择是否继续游戏(Y/y为是，N/n为否): n\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "正在退出游戏，感谢您的使用，欢迎下次使用...\n"
     ]
    }
   ],
   "source": [
    "import time\n",
    "import random\n",
    "\n",
    "print(\"欢迎使用GuessGame小游戏！\\n\")\n",
    "sel = str(input('是否开始游戏(Y/y为是，N/n为否):'))  # 获取用户选择\n",
    "\n",
    "\n",
    "# 定义数字猜测游戏函数\n",
    "def guess():\n",
    "    tmp = random.randint(0, 101)  # 生成0-100的随机数\n",
    "    mon = 5000  # 定义初始金币数量\n",
    "    print('系统随机幸运数字已生成,友情提示数字范围提醒:0-100(包括0和100)，游戏开始')\n",
    "    while mon >= 500:  # 设置循环条件，满足条件循环，不满足退出\n",
    "        tmp = tmp\n",
    "        # print(tmp)  # 打印出系统生成的随机数，用于验证可靠性\n",
    "        using = int(input('请输入您猜测的数字:'))\n",
    "        # 判断输入的数字与系统生成的随机数的关系\n",
    "        if using < 0 or using > 100:\n",
    "            print('对不起，您输入的数字超出预定范围，请重新输入')\n",
    "        elif using > tmp:\n",
    "            print('对不起，您输入的数字大于幸运数，金币数量减500，剩余金币：', mon - 500)\n",
    "            mon = mon - 500\n",
    "        elif using < tmp:\n",
    "            print('对不起，您输入的数字小于幸运数,金币数量减500，剩余金币：', mon - 500)\n",
    "            mon = mon - 500\n",
    "        elif using == tmp:\n",
    "            print('恭喜您猜对了，金币数量加3000，现有金币数量{},本轮幸运数字为：{}'.format(mon + 3000, tmp))\n",
    "            mon = mon + 3000\n",
    "            res = str(input('本轮游戏结束，请选择是否继续游戏(Y/y为是，N/n为否):'))\n",
    "            if res == '':\n",
    "                res = str(input(\"您输入的字符为空，请重新输入：\"))\n",
    "                if res.upper() == 'Y':\n",
    "                    print('正在重新生成系统随机幸运数字...')\n",
    "                    tmp = random.randint(0, 101)  # 生成0-100的随机数\n",
    "                    print(\"新的幸运数字已生成，游戏继续...\")\n",
    "                elif res.upper() == 'N':\n",
    "                    print(\"正在退出游戏，感谢您的使用，欢迎下次使用...\")\n",
    "                    time.sleep(1)\n",
    "                    break\n",
    "                else:\n",
    "                    print('输入错误！')\n",
    "                    break\n",
    "            else:\n",
    "                if res.upper() == 'Y':\n",
    "                    print('正在重新生成系统随机幸运数字...')\n",
    "                    tmp = random.randint(0, 101)  # 生成0-100的随机数\n",
    "                    print(\"新的幸运数字已生成，游戏继续...\")\n",
    "                elif res.upper() == 'N':\n",
    "                    print(\"正在退出游戏，感谢您的使用，欢迎下次使用...\")\n",
    "                    time.sleep(1)\n",
    "                    break\n",
    "                else:\n",
    "                    print('输入错误！')\n",
    "                    break\n",
    "        else:\n",
    "            print(\"输入错误！\")\n",
    "            break\n",
    "    else:\n",
    "        print('目前剩余金币为%d，不足以继续游戏，游戏退出'%(mon))\n",
    "\n",
    "\n",
    "if sel.upper() == 'Y':  # 判断用户的选择\n",
    "    print(\"正在进入游戏\\n\")\n",
    "    time.sleep(0.5)  # 时间暂停0.5秒\n",
    "    guess()\n",
    "elif sel.upper() == 'N':\n",
    "    print('正在退出程序...')\n",
    "    time.sleep(1)\n",
    "    exit()\n",
    "else:\n",
    "    print(\"输入错误！\")\n",
    "    exit()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
